﻿using StockAccessors;
using StockModel;

namespace StockEngine.RealTime
{
    internal static class AccessorStockToQuotationConverter
    {
        #region Public Methods

        public static Quotation ConvertItem(AccessorStockQuote item)
        {
            Quotation result = new Quotation();

			result.Acquisition = item.Acquisition;

            int buyersQuantity = item.BidVolume == null ? 0 : item.BidVolume.Value;
            decimal buyPrice = item.BidValue == null ? 0 : item.BidValue.Value;
			int sellersQuantity = item.AskVolume == null ? 0 : item.AskVolume.Value;
            decimal sellPrice = item.AskValue == null ? 0 : item.AskValue.Value;
            result.Value = item.LastValue == null ? 0 : item.LastValue.Value;
            result.Volume = item.Volume == null ? 0 : item.Volume.Value;

			result.Buyers.Add(new Order(buyPrice, buyersQuantity));
			result.Sellers.Add(new Order(sellPrice, sellersQuantity));

            return result;
        }

        #endregion
    }
}
